package com.zzzyh.forumsystemclient.services.impl;

import com.zzzyh.forumsystemclient.dao.AlbumMapper;
import com.zzzyh.forumsystemclient.dao.PhotoMapper;
import com.zzzyh.forumsystemclient.model.Album;
import com.zzzyh.forumsystemclient.services.IAlbumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AlbumServiceImpl implements IAlbumService {
    @Autowired
    private AlbumMapper albumMapper;
    @Autowired
    private PhotoMapper photoMapper;

    @Override
    public List<Album> list() {
        List<Album> list = albumMapper.list();
        for (Album album : list){
            album.setPhotoNum(albumMapper.getPhotoNum(album.getId()));
        }
        return list;
    }

    @Override
    public Album getById(Long albumId) {
        Album album = albumMapper.selectByPrimaryKey(albumId);
        album.setPhotoNum(albumMapper.getPhotoNum(album.getId()));
        return album;
    }
}
